# -*- coding: utf-8 -*-
# @File     : permissions.py
# @Author   : bingjia
# @Time     : 2020/8/8 14:55
# @Desc     : 项目权限


from ..base.api import permissions
from ..base.api.permissions import IsSuperUser
from ..base.api.permissions import BasePermission
from ..base.api.permissions import IsAuthenticated

from ..permissions.permissions import IsProjectAdmin
from ..permissions.permissions import IsProjectMembership


class RolePermission(BasePermission):
    """
    团队权限
    """
    # 增删改查
    list_perms = IsAuthenticated() & IsProjectMembership()
    create_perms = IsAuthenticated() & IsProjectAdmin()
    destroy_perms = IsAuthenticated() & IsProjectAdmin()
    partial_update_perms = IsAuthenticated()


class MembershipPermission(BasePermission):
    """
    团队权限
    """
    # 增删改查
    list_perms = IsAuthenticated()
    create_perms = IsAuthenticated()
    destroy_perms = IsAuthenticated() & IsProjectAdmin()
    partial_update_perms = IsAuthenticated() & IsProjectAdmin()


class ProjectPermission(BasePermission):
    """
    项目权限
    """
    # 全局权限
    global_perms = None
    enough_perms = IsSuperUser()

    # 增删改查
    list_perms = IsAuthenticated()
    create_perms = IsAuthenticated()
    destroy_perms = IsAuthenticated() & IsProjectAdmin()
    retrieve_perms = IsAuthenticated() & IsProjectMembership()
    partial_update_perms = IsAuthenticated() & IsProjectAdmin()

    # 其它操作权限
    add_map_perms = IsAuthenticated() & IsProjectAdmin()
    add_report_perms = IsAuthenticated() & IsProjectAdmin()


class ProjectAdminPermission(BasePermission):
    """
    项目管理权限
    """
    # enough_perms = IsSuperUser()

    list_perms = IsAuthenticated()


